#include <cstdio>
using namespace std;
long long f(long long a, long long b, long long mod) {
    long long ans = 1;
    if (b == 0) {
        return ans % mod;
    }
    while (b > 0) {
        if (b % 2 == 1) {
            ans = (ans * a) % mod;
        }
        b /= 2;
        a = (a * a) % mod;
    }
    return ans;
}
int main () {
    long long x, y, k;
    scanf ("%ld%ld%ld", &x, &y, &k);
    printf ("%ld\n", f(x, y, k));
    return 0;
}